<script setup lang="ts">
import Post from '@/components/post/index.vue'
import { usePostStore } from '@/stores/modules/post'
import { computed } from 'vue'

const postStore = usePostStore()

// 直接使用计算属性获取当前用户的帖子
const myPosts = computed(() => postStore.getPostOfSelf)
</script>

<template>
  <div>
    <!-- 使用 v-for 遍历 myPosts 渲染 Post 组件 -->
    <Post
      v-for="post in myPosts"
      :key="post.post.id"
      :postData="{
        // 处理可能为 null 的情况
        cover: post.post.pictureBase64 || '',
        // 类型转换
        username: post.username,
        title: post.post.title,
        desc: post.post.content.substring(0, 10),
        publishTime: post.post.createTime,
        commentCount: 0,
        id: post.post.id,
        userId: post.post.userId,
      }"
    />
  </div>
</template>

<style lang="scss" scoped></style>
